/**
 * 
 */
package com.scholarone.s1exporttool.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.stereotype.Repository;

import com.scholarone.s1exporttool.domain.Resource;

/**
 * @author prabz
 *
 */
@Repository("exportDao")
public class ExportDaoImpl implements ExportDao{
	
	@Autowired
	private SimpleJdbcTemplate simpleJdbcTemplate;

	/**
	 * @return
	 */
	public SimpleJdbcTemplate getSimpleJdbcTemplate() {
		return simpleJdbcTemplate;
	}

	/**
	 * @return
	 */
	public List<Resource> getResources() {
	      String query = "select resource_name_id, name from resource_name fetch first 10 rows only";
	      return getSimpleJdbcTemplate().query(query, new ParameterizedRowMapper<Resource>() {
	            public Resource mapRow(ResultSet rs, int row) throws SQLException {
	            	Resource resource = new Resource();
	            	resource.setId(rs.getInt(1));
	            	resource.setName(rs.getString(2));
	               return resource;
	            }
	      });
	   }	
}
